import State
import string

# Class for holding path, peer_ip, switch count, intervals for Paths
class Path:
    def __init__ (self, path, peerAs, switches = 0, actTime = 0, lastActTime = 0, actCount = 0):
        self.path = path
        self.peerAs = peerAs
        self.state = State.State(actCount, lastActTime, switches, actTime)

    def switchPath(self, newPath, utcTime):
        self.path = newPath
        self.state.addSwitch()
        
    def startPath(self, newPath, utcTime):
        self.path = newPath
        self.state.activate(utcTime)      
        self.state.addSwitch()
        
    def stopPath(self, utcTime):
        self.state.deactivate(utcTime)
        
    def containsPath(self, testPath):
        return self.path == testPath
    
    def reset(self, utcTime):
        self.state.reset(utcTime)
    
    def setPath(self, newPath):
        self.path = newPath
    
    def isActive(self):
        return self.state.isActive()
    
    def totalActiveTime(self, utcTime):
        return self.state.activeTime(utcTime)

    def printState(self, utcTime):
        actTime = self.totalActiveTime(utcTime)
        print "AS: %s Switches: %s Path: %s Total Active: %s Is Active: %s" % (self.peerAs, self.state.switchCount(), self.path, actTime, self.isActive())
        
    def pathAsList(self):
        return ",".join(map(str, self.path))   